package com.dzt.androidframework.view;

import android.os.Bundle;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;

import com.dzt.androidframework.R;
import com.dzt.androidframework.activity.ActivityTitle;
import com.lljjcoder.style.citythreelist.ProvinceActivity;

import org.xutils.view.annotation.ViewInject;

import java.util.ArrayList;
import java.util.List;

public class CityPickerActivity extends ActivityTitle {

	@ViewInject(R.id.citypicker_rv)
	RecyclerView mCitypickerRv;

	CityPickerAdapter mCityPickerAdapter;

	String[] mTitle = new String[] { "城市列表", "ios选择器", "三级列表"/*, "仿京东"*/ };

	Integer[] mIcon = new Integer[] { R.drawable.ic_citypicker_onecity, R.drawable.ic_citypicker_ios,
			R.drawable.ic_citypicker_three_city/*, R.drawable.ic_citypicker_jingdong*/ };

	private List<CityPickerStyleBean> mCityPickerStyleBeanList = new ArrayList<>();

	@Override
	protected void initData(Bundle savedInstanceState) {
		for (int i = 0; i < mTitle.length; i++) {
			CityPickerStyleBean cityPickerStyleBean = new CityPickerStyleBean();
			cityPickerStyleBean.setTitle(mTitle[i]);
			cityPickerStyleBean.setResourId(mIcon[i]);
			mCityPickerStyleBeanList.add(cityPickerStyleBean);
		}
	}

	@Override
	protected String[] initPermissions() {
		return new String[0];
	}

	@Override
	protected int getLayoutId() {
		return R.layout.activity_city_picker;
	}

	@Override
	protected void initParams() {
		setTitleView(R.string.view_5);
		mCitypickerRv.addItemDecoration(new DividerGridItemDecoration(this));
		mCitypickerRv.setLayoutManager(new GridLayoutManager(this, 3));

		mCityPickerAdapter = new CityPickerAdapter(CityPickerActivity.this, mCityPickerStyleBeanList);
		mCitypickerRv.setAdapter(mCityPickerAdapter);
		mCityPickerAdapter.setmOnItemClickListener(new CityPickerAdapter.OnItemClickListener() {
			@Override
			public void onItemClick(View view, int position) {

				if (null != mCityPickerAdapter && null != mCityPickerAdapter.getData()
						&& !mCityPickerAdapter.getData().isEmpty()
						&& null != mCityPickerAdapter.getData().get(position)) {
					gotoDetail(mCityPickerAdapter.getData().get(position).getResourId());
				}
			}
		});
	}

	/**
	 * 选择相关样式
	 * @param resourId
	 */
	private void gotoDetail(int resourId) {
		switch (resourId) {
			case R.drawable.ic_citypicker_onecity:
				startActivity(CityPickerListActivity.class, null);
				break;

			case R.drawable.ic_citypicker_ios:
				startActivity(CityPickerWheelActivity.class, null);
				break;

			case R.drawable.ic_citypicker_three_city:
				startActivity(ProvinceActivity.class, null);
				break;
            /*
            case R.drawable.ic_citypicker_jingdong:
                ActivityUtils.getInstance().showActivity(MainActivity.this, ProvinceActivity.class);
                break;
            */
			default:
				break;
		}
	}
}
